﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Runtime.InteropServices;

    public class CartController
    {
        public void BuildFromSeedOrder(int PortalID, string OrderGUID)
        {
            NB_Store_OrdersInfo orderByGUID = new OrderController().GetOrderByGUID(OrderGUID);
            if (orderByGUID != null)
            {
                CurrentCart.CreateCartFromOrder(Conversions.ToString(PortalID), orderByGUID.OrderID, false);
            }
        }

        public void DeleteCart(string CartID)
        {
            DataProvider.Instance().DeleteNB_Store_Cart(CartID);
        }

        public void DeleteCartItem(int ItemID)
        {
            DataProvider.Instance().DeleteNB_Store_CartItems(ItemID);
        }

        public void DeleteOldCarts(int PortalID, int CartMins, int OrderMins)
        {
            DataProvider.Instance().DeleteOldCarts(PortalID, CartMins, OrderMins);
        }

        public NB_Store_CartInfo GetCart(string CartID)
        {
            return (NB_Store_CartInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_Cart(CartID), typeof(NB_Store_CartInfo));
        }

        public NB_Store_CartItemsInfo GetCartItem(int ItemID)
        {
            return (NB_Store_CartItemsInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_CartItems(ItemID), typeof(NB_Store_CartItemsInfo));
        }

        public NB_Store_CartItemsInfo GetCartItemByOptCode(string CartID, string OptCode)
        {
            return (NB_Store_CartItemsInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_CartItemsByOptCode(CartID, OptCode), typeof(NB_Store_CartItemsInfo));
        }

        public ArrayList GetCartItemList(string CartID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_CartItemss(CartID), typeof(NB_Store_CartItemsInfo));
        }

        public ArrayList GetCartList(string CartID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_CartList(CartID), typeof(NB_Store_CartListInfo));
        }

        public int GetCartModelQty(int PortalID, int ModelID, string CartID = "")
        {
            return DataProvider.Instance().GetCartModelQty(PortalID, ModelID, CartID);
        }

        public void UpdateObjCart(NB_Store_CartInfo objInfo)
        {
            DataProvider.Instance().UpdateNB_Store_Cart(objInfo.CartID, objInfo.PortalID, objInfo.UserID, objInfo.DateCreated, objInfo.OrderID, objInfo.VATNumber, objInfo.PromoCode, objInfo.CountryCode, objInfo.ShipType, objInfo.BankTransID, objInfo.BankHtmlRedirect, objInfo.ShipMethodID, objInfo.CartDiscount, objInfo.XMLInfo, objInfo.Referrer);
        }

        public int UpdateObjCartItem(NB_Store_CartItemsInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_CartItems(objInfo.ItemID, objInfo.CartID, objInfo.Quantity, objInfo.DateCreated, objInfo.UnitCost, objInfo.ModelID, objInfo.OptCode, objInfo.ItemDesc, objInfo.Discount, objInfo.Tax, objInfo.ProductURL, objInfo.XMLInfo, objInfo.StaticAmts);
        }
    }
}

